<template>
  <div>
    <!-- 审核 -->
    <div style="margin-bottom: 10px;margin-top: 10px;">
          <el-input v-model="createUserName"  placeholder="请输入产物名" suffix-icon="el-icon-search" style="width: 200px"
          @keyup.enter.native="loadPost"></el-input>
          <el-select v-model="activityId"  placeholder="请选择活动"  style="margin-left: 10px">
           <el-option
            v-for="item in activityIds"
            :key="item.value"
            :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>

       
     
          <el-button type="primary" style="margin-left: 10px" @click="loadPost">查询</el-button>
          <el-button type="success" @click="resetParam">重置</el-button>
        
      </div>
  <el-table :data="tableData"
  :header-cell-style="{background:'#f2f5fc',color:'#555'}" border>
      <el-table-column prop="id" label="ID" width="160">
      </el-table-column>

      <el-table-column prop="activityId" label="活动名" width="160" :formatter="titleFormate">
      </el-table-column>
 
      <el-table-column prop="achieveId" label="产物名"  width="160"  :formatter="achievementFormate">
      </el-table-column>

      <el-table-column prop="status" label="状态"  width="160" :formatter="statusFormate">
      </el-table-column>

      

      <el-table-column prop="createUserName" label="创建人姓名"  width="160">
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间"  width="160">
      </el-table-column>


      
      <el-table-column prop="updateUserName" label="修改人姓名"  width="160">
      </el-table-column>
      <el-table-column prop="updateTime" label="修改时间"  width="160">
      </el-table-column>


      
      <el-table-column prop="operate" label="操作">
          <template slot-scope="scope">
          <el-button size="small" type="success" @click="mod(scope.row)">审核</el-button>
          </template>
      </el-table-column>

  </el-table>
      <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="pagenum"
              :page-sizes="[2, 5, 10, 20]"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
      </el-pagination>
      <el-dialog
              title="活动审核"
              :visible.sync="centerDialogVisible"
              width="80%"
              center>


              <p>活动信息</p>
              <p>活动标题: <span>{{ActivityData.title}}</span></p>
              <p>活动介绍: <span>{{ ActivityData.content }}</span></p>
              <p></p>
              <p></p>
              <p>成果信息</p>
              <p>成果名: <span>{{AchievementData.name}}</span></p>
              <p>成果描述: <span>{{AchievementData.content}}</span></p>
              <p>成果附件: <span>{{AchievementData.filePath}}</span></p>
              <p></p>
              <p></p>
              <p>参赛用户信息</p>
              <p>用户账号: <span>{{tableData.createUserName}}</span></p>
              <p>真实姓名: <span>{{ tableData.name }}</span></p>
              <el-form :model="form" ref="form" label-width="100px" class="demo-ruleForm">
            
            <el-form-item label="状态" prop="status">
                <el-select v-model="form.status" placeholder="请选择属于状态">
              <el-option label="申请中" value="1"></el-option>
              <el-option label="审核通过" value="2"></el-option>
              <el-option label="审核未通过" value="3"></el-option>
            
               </el-select>
            </el-form-item>

            <el-form-item label="审核备注" prop="bak">
                    <el-input  v-model="form.bak" placeholder="审核备注非必填"></el-input>
            </el-form-item>

        </el-form>

        <span slot="footer" class="dialog-footer">
          <el-button @click="centerDialogVisible = false">取 消</el-button>
         <el-button type="primary" @click="save">确 定</el-button>
          </span>
          <!-- 上传图片 -->
      </el-dialog>
  
  </div>
</template>

<script>
    export default {
        name: "UnitList",
        data() {
         
            return {
        activityId:-1,
        activityIds:[{
            value: -1,
            label: '全部活动'
            }, {
              value: 1,
              label: '重庆财经学院第三届讯飞杯'
                },
                {
              value: 2,
              label: '重庆马拉松赛事'
                },
              ],
              activiTy:[],
            achievement:[],
              ActivityData:[],
              tableData: [],
              AchievementData:[],
              pagenum:1,
              pageSize:2,
              createUserName:'',
              total:0,
              name:'',
              form:{
                status:1,
                bak:'',
              },
              
                centerDialogVisible:false,
            

            }

        },
        methods:{
            achievementFormate(row, index){
                for(let i in this.AchievementData){
                    if(this.AchievementData[i].id==row.achieveId){
                        return this.AchievementData[i].name
                    }
                }
            },
            titleFormate(row, index){
                for(let i in this.ActivityData){
                    if(this.ActivityData[i].id==row.activityId){
                        return this.ActivityData[i].title
                    }
                }
            },
              // 显示状态
           statusFormate(row, index){
                if(row.status == 1){
                    return "筹划中";
                }else if(row.status == 2){
                    return "已发布";
                }else if(row.status == 3){
                    return "已下架";
                }},
            resetForm() {
                this.$refs.form.resetFields();
            },
         
         
          
      
            resetParam(){
                this.createUserName='',
                this.status=-1
           
                
            },
            handleSizeChange(val) {
                
                this.pagenum=1
                this.pageSize=val
                this.loadPost()
            },
            handleCurrentChange(val) {
                
                this.pagenum=val
                this.loadPost()
            },
          
        
            loadPost(){
             
             this.$axios.get(this.$httpUrl+'/jk/activity/apply/listT?createUserName='+this.createUserName+'&activityId='+this.activityId+'&pagenum='+this.pagenum +'&pageSize='+this.pageSize
             ).then(res=>res.data).then(res=>{
              
                 if (res.resCode=='000000'){
                     this.tableData=res.data.records
                     this.total=res.data.total

                 }else{
                     alert('获取数据失败')
                 }

             })
         },
       
            mod(row){
              //    赋值到表单
                  this.centerDialogVisible=true
                  this.$nextTick(()=>{
                     
                      this.form.bak = row.bak
                      this.form.status = row.status
            
                  })
             
                  console.log(this.ActivityData+'fjiew')
                  for(let i in this.ActivityData){
                    if(this.ActivityData[i].id==row.activityId){
                        return this.ActivityData[i].title ,this.ActivityData[i].content
                    }
                }
                for(let i in this.AchievementData){
                    if(this.AchievementData[i].id==row.achieveId){
                        return this.AchievementData[i].name,this.AchievementData[i].content,this.AchievementData[i].filePath
                    }
                }
                 
               
              },
            //   根据id查询活动和成果
            // Activity(id){
               
            //     this.$axios.get(this.$httpUrl+' /jk/admin/activity/detail?id='+id).then(res=>res.data).then(res=>{
                
             
            //     if (res.resCode=='000000'){
                    
            //         console.log("huod"+res.data)
            //         this.activiTy=res.data
            //        this.$message({
            //                  message: '操作成功',
            //                  type: 'success'
            //              });  
            //     }else{
            //        this.$message({
            //                  message: '获取数据失败',
            //                  type: 'error'
            //              });
            //     }

            // })
            // },
            // Achievement(id){
            //     this.$axios.get(this.$httpUrl+'/jk/admin/achievement/detail?id='+id).then(res=>res.data).then(res=>{
            //     if (res.resCode=='000000'){
            //         console.log("成"+res.data)
            //         this.achievement=res.data
            //        this.$message({
            //                  message: '操作成功',
            //                  type: 'success'
            //              });  
            //     }else{
            //        this.$message({
            //                  message: '获取数据失败',
            //                  type: 'error'
            //              });
            //     }

            // })
            // },
            
            
              // 修改  /examine
              doMod(){
                  this.$axios.put(this.$httpUrl+'/jk/activity/apply/examine?status='+this.form.status).then(res=>res.data).then(res=>{
  
                      if (res.resCode=='000000'){
                          this.$message({
                              message: '操作成功',
                              type: 'success'
                          });
                          //成功之后离开刷新页面
  
                          this.centerDialogVisible=false
                          this.loadPost()
                          // this.resetForm()
  
                      }else{
                          this.$message({
                              message: '操作失败',
                              type: 'error'
                          });
                      }
  
                  })
              },
            save(){
                  this.$refs.form.validate((valid) => {
                      if (valid) {                      
                              this.doMod()  
                      } else {
                          console.log('error submit!!');
                          return false;
                      }
                  });
  
              },

       //  获取活动
       loadActivity(){
             
             this.$axios.get(this.$httpUrl+'/jk/admin/activity/listAll').then(res=>res.data).then(res=>{
                
                 if (res.resCode=='000000'){
                     this.ActivityData=res.data
                     console.log(this.ActivityData)

                 }else{
                     alert('获取数据失败')
                 }

             })
         },
        // 获取成果
            loadAchievement(){
             
             this.$axios.get(this.$httpUrl+'/jk/admin/achievement/listAll').then(res=>res.data).then(res=>{
                
                 if (res.resCode=='000000'){
                     this.AchievementData=res.data
                     console.log(this.AchievementData)
                 }else{
                     alert('获取数据失败')
                 }

             })
         },     

        },
        beforeMount() {
            this.loadAchievement()
            this.loadActivity()
            this.loadPost();

        }
    }
</script>

<style>

</style>